home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir42 / bltc18z.zip / !Q&A.TXT < prev    next >
Text File  |  1993-08-31  |  10KB  |  213 lines

  1. Questions & Answers
  2.  
  3. Q: What is BULLET?
  4.  
  5. A: BULLET is a library of program modules that together let the programmer
  6.    develop and create software that can manage huge amounts of data on
  7.    disk using the industry-standard DBF data file format. It also uses high-
  8.    speed b-tree index files to manage keyed data file access.
  9.  
  10.  
  11. Q: What compiler is BULLET for?
  12.  
  13. A: BULLET can be used by nearly all DOS compilers. It's written entirely in
  14.    assembly language. Because of this, it does not require any particular
  15.    programming language or compiler vendor. The 4 requirements are listed
  16.    in the !WHATIS.TXT file.
  17.  
  18.  
  19. Q: Why do I need BULLET when all I need to handle are small amounts of data?
  20.  
  21. A: BULLET can deal with a database as small as 1 record or as large as several
  22.    million. While your current needs may be small, your future needs are bound
  23.    to expand. BULLET can work with you now, and later, even if you switch
  24.    development platforms by moving to another compiler. And BULLET is fast,
  25.    it can deal with a database with millions of records as easily as it can
  26.    with just a few.
  27.  
  28.  
  29. Q: But b-tree stuff, isn't that hard?
  30.  
  31. A: Everything associated with maintaining the database, its data files and its
  32.    index files, is done behind-the-scenes by BULLET. You just specify how the
  33.    data record is to look by specifying the number of fields, their lengths and
  34.    types, and then specify how you want your index files to be based.
  35.  
  36.  
  37. Q: So how do I design my data record?
  38.  
  39. A: You probably have a pretty good idea, already. A good way to determine what
  40.    should go into a database is what you want to come out of it. For example,
  41.    if you're doing a mailing list program, you'll want to have at least the
  42.    name, perhaps broken into first name and last. Also you'll need the mailing
  43.    address--4 lines is usually enough, so you'll want 4 separate address line
  44.    fields. Then there's the State and ZIP, possibly even country. That's the
  45.    minimum. It would look something like this:
  46.  
  47.    FIRSTNAME field of 15 characters; LASTNAME field of 19 characters; ADDR1
  48.    field of 34 characters, ADDR2, ADDR3, ADDR4 as ADDR1; State field of 2
  49.    characters, and ZIP a field of 5 (or 9 if ZIP+4) characters. You could
  50.    specify the ZIP as a numeric field if you wanted.
  51.  
  52.    You'll notice that the longest field is 34 characters. Why? Because most
  53.    mailing labels are 3.5 inches, about 34 characters across. Since the first
  54.    name and last are usually put on the same line, their total should be 34.
  55.  
  56.    You'll probably want to add more fields like telephone number, last time
  57.    written to, oh, just about anything that you'd think would be important to
  58.    know. There you go, you've just designed your data record.
  59.  
  60.  
  61. Q: Then what?
  62.  
  63. A: Then decide how you need to access this data. You'll want to access it at
  64.    least by name, so one index you'll want is on the name. While you could
  65.    specify the entire name be used as a key, say LASTNAME+FIRSTNAME, this is
  66.    a bit of overkill. Instead, you may want to use just a portion of the name.
  67.    A good candidate would be SUBSTR(LASTNAME,1,5)+SUBSTR(FIRSTNAME,1,1). This
  68.    sets up a key that's only 6 bytes long. The first method, using all the
  69.    name, would be 34 bytes long. By keeping your keys short you'll keep your
  70.    index files small and your index performance high. And yes, you can also
  71.    mix numeric field types with character field types in your key expressions.
  72.  
  73.  
  74. Q: But what if I have two or more names that are identical, or very similar
  75.    but have these parts of the names the same?
  76.  
  77. A: BULLET lets you specify if your index files allow only unique key entries or
  78.    whether duplicate keys are permitted. When keying on a name you should have
  79.    your index file allow duplicate keys. What BULLET does is number these
  80.    identical keys by adding a suffix to each key (called an enumerator). This
  81.    enumerator allows the index algorithm to treat each key as a different key.
  82.    If you search the index for all matches in the first 6 characters of the
  83.    key (the enumerators will always be different) these similar names will
  84.    be found in consecutive order. To find out if the key you've just accessed
  85.    is the actual person you had in mind, you'd scan the data record associated
  86.    with that key for other information, such as middle initial, address,
  87.    anything that would make that person recognizable from another with a
  88.    similar key. If it isn't what you're looking for, get the next key and data
  89.    record, and so on until the first 6 characters of the key no longer are the
  90.    6 you're looking for.
  91.  
  92.  
  93. Q: So I've got my data record designed and also my primary index file. What
  94.    else should I do?
  95.  
  96. A: Now that the database is designed most of the "unknown" is taken care of.
  97.    What comes next depends on how you, yourself, program. What I often do
  98.    next is detail exactly what I want the output to be. That way, I've got
  99.    the front and the back and just need to do the middle. The middle is where
  100.    the fun's at. You'll be amazed at just how few of your in-the-middle coding
  101.    is spent on managing the database. BULLET takes care of all the little
  102.    details. You just need to give it the data and tell it what to do with
  103.    it. Or you tell it what to get and it comes back with what you requested.
  104.    You then do whatever you want with that data.
  105.  
  106.  
  107. Q: I've looked at the header file and it sure has a lot of commands. You're
  108.    telling me that this is simple?
  109.  
  110. A: Yes. Once you've created your data and index files, those mid-level
  111.    routines are not often used. Almost everything you do in your in-the-middle
  112.    coding will use the high-level routines. The InsertXB and UpdateXB routines
  113.    handle adding new or changing existing data, and the GetFirstXB, GetNextXB,
  114.    etc., routines handle getting the data. 90% of the time these are the
  115.    routines your program will be using.
  116.  
  117.  
  118. Q: What about all those packs? How can I keep them straight?
  119.  
  120. A: The good thing about modern programming langauges is that they let you
  121.    build reusable code. The ideal way to use BULLET is to build reusable
  122.    code objects in your programming langauge of choice and hide the down-and-
  123.    dirty aspects of dealing with the various packs in those objects. For
  124.    example, a create key routine could be written once and that object used
  125.    for all your other programming projects:
  126.  
  127.       DECLARE FUNCTION CreateNewIndex% (filen$, kx$, kflags%, XBlink%)
  128.  
  129.       FUNCTION CreateNewIndex(filename$, kx$, keyflags, XBlink)
  130.  
  131.       DIM CKP AS CreateKeyPack
  132.       DIM TmpFile AS STRING * 80
  133.       DIM TmpExp AS STRING * 136
  134.  
  135.       TmpFile = filename$ + CHR$(0)
  136.       TmpExp = kx$ + CHR$(0)
  137.  
  138.       CKP.Func = CreateKXB
  139.       CKP.FilenamePtrOff = VARPTR(TmpFile)
  140.       CKP.FilenamePtrSeg = VARSEG(TmpFile)
  141.       CKP.KeyExpPtrOff = VARPTR(TmpExp)
  142.       CKP.KeyExpPtrSeg = VARSEG(TmpExp)
  143.       CKP.XBlink = XBlink
  144.       CKP.keyflags = keyflags
  145.       CKP.CodePageID = -1
  146.       CKP.CountryCode = -1
  147.       CKP.CollatePtrOff = 0
  148.       CKP.CollatePtrSeg = 0
  149.       stat = BULLET(CKP)
  150.       CreateNewIndex = stat
  151.  
  152.       END FUNCTION
  153.  
  154.    The TmpFile and TmpExp were used in this QuickBASIC example so that the
  155.    string data is assigned to a fixed-length string. VARSEG/VARPTR operate
  156.    on fixed-length strings identically in both BASIC 7 and QuickBASIC 4.5.
  157.    If you want to forgo this compatibility you could use a var-len string
  158.    and the BASIC SADD() function instead of VARPTR. I find using the
  159.    temporary fixed-length strings just as easy since a CHR$(0) needs to
  160.    be appended to the string in any case. And they are temporary strings--
  161.    as soon as the CreateNewIndex() routine exits, the memory assigned to the
  162.    Tmp strings is released.
  163.  
  164.    So, once you write this create index object, you can reuse it over and
  165.    over again without needing to recode it every time. Just a simple
  166.  
  167.    stat = CreateNewIndex(filename$,keyexpression$,keyflags,XBlink)
  168.  
  169.    is all you need to put in your in-the-middle code. Oh, the key expression,
  170.    keyflags, and XBlink are all explained under CreateKXB in CZ.
  171.  
  172.  
  173. Q: I think I'm getting the hang of it. What's next?
  174.  
  175. A: Jump in and start coding. You may want to look over, maybe even print out,
  176.    one of the example programs. The BB_CAI10.BAS is straight forward, try
  177.    that. If you have any questions, just pop-up CZ. It's all in there.
  178.  
  179.  
  180. Q: Sounds good. But, tell me, what is the first thing I'm likely to muff?
  181.  
  182. A: Nothing serious. Just make sure that your record structure in memory
  183.    reserves the first byte for the delete tag. Also, make sure that the field
  184.    descriptors you assigned when you created the data file match your in-memory
  185.    structure, i.e., if you've created a data file (using CreateDXB) with say, 3
  186.    fields, each 25 characters long, make sure that your in-memory structure is
  187.    also 3 fields, each 25 characters:
  188.  
  189.       TYPE ExampleRecordTYPE
  190.       tag AS STRING * 1
  191.       Field1 AS STRING * 25
  192.       Field2 AS STRING * 25
  193.       Field3 AS STRING * 25
  194.       END TYPE
  195.  
  196.    Note: it is allowable to alias your physical fields but the total length
  197.    must match the total length of the DBF data record. (Alias meaning that
  198.    instead of using Field1 AS STRING * 25, you use Field1a AS STRING 13 and
  199.    Field1b AS STRING 12. Be sure you know what you're doing!--the IDEMO.BAS
  200.    program uses this technique (not in the strict sense of alias) by using a
  201.    single 4000-byte in-memory record since it can't know beforehand what
  202.    structure a random DBF file has.)
  203.  
  204.    Also, the transaction routines (InsertXB, UpdateXB, ReindexXB, and the
  205.    LockXBs) return a transaction index rather than a completion code. Be sure
  206.    to check the documentation for the routines.
  207.  
  208. Q: I'm off.
  209.  
  210. A: So am I, but be sure to...
  211.  
  212.    ...Read the manual! Until you do you can't take full advantage of BULLET.
  213.